#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MAXSIZE 50

typedef struct{
	int no;
	char name[10];
	double score;
}Student;

typedef struct{
	Student *stus;
	int lenght;
}SqList;

void getSqList(SqList &p);
void addStudent(SqList *p,Student &s);
void showAll(SqList *p);
void deleteAll(SqList &p);
void deleteStudentFromSqList(SqList *p,Student *s);
int main(){
	SqList sqList;
	Student s1={43,"zhangsan",34},s2={44,"lisi",23},s3={45,"wangwu",23};
	getSqList(sqList);
	addStudent(&sqList,s1);
	addStudent(&sqList,s3);
	addStudent(&sqList,s2);
	showAll(&sqList);
	deleteStudentFromSqList(&sqList,&s2);
	showAll(&sqList);
	return 0;
}

void getSqList(SqList &p){
	p.stus=new Student[MAXSIZE];
	p.lenght=0;
}

void addStudent(SqList *p,Student &s){
	for (int i = 0; i < p->lenght; i++)
	{
		if (s.no>(p->stus+i)->no&&i<p->lenght-1&&s.no<(p->stus+i+1)->no)
		{
			for (int j = p->lenght; j>i+1; j--)
			{
				// (p+j)->stus=(p+j-1)->stus;
				*(p->stus+j)=*(p->stus+j-1);
			}
			// (p+i)->stus=&s;
			*(p->stus+i+1)=s;
			p->lenght++;
			return;
		}
	}
	*(p->stus+p->lenght)=s;
	p->lenght+=1;
}


void showAll(SqList *p){
	int i;
	Student s;
	for(i=0;i<p->lenght;i++){
		s=*(p->stus+i);
		printf("the %d student,name is %s, no is %d ,score is %f \n",i+1,s.name,s.no,s.score);
	}
}

void deleteStudentFromSqList(SqList *p,Student *s){
	for (int i = 0; i < p->lenght; i++)
	{
		if ((p->stus+i)->no==s->no)
		{
			for (int j = i; j < p->lenght; j++)
			{
				*(p->stus+j)=*(p->stus+j+1);
			}
			p->lenght--;
			break;
		}
		
	}
	
}
/*void deleteAll(SqList &p){
	int i;
	for(i=0;i<p.lenght;i++){
		delete (p.stus+i)->name;
	}
	delete p.stus;
}*/